package com.me.chat.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)//开启@prePost注解
public class SecurityFormConfig extends WebSecurityConfigurerAdapter {

    @Bean
    public AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();//用于oauth2的密码验证管理器
    }

    @Autowired
    SecuritySecertConfig securitySecertConfig;

    @Bean
    PasswordEncoder passwordEncoder(){//加密，在登录接口输入参数，就可以自动转化密码
        return new BCryptPasswordEncoder();
    }//加密算法
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/**")
                .permitAll()//以上路径释放
                .and()
                .csrf()//其实这个关闭csrf才是主要配置
                .disable();
    }
}
